home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume13 / conf / part03 < prev    next >
Encoding:
Internet Message Format  |  1988-03-13  |  33.9 KB

  1. Subject:  v13i100:  Multi-user conferencing system, Part03/05
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Keith Gabryelski <ag@crash.cts.com>
  7. Posting-number: Volume 13, Issue 100
  8. Archive-name: conf/part03
  9.  
  10. #! /bin/sh
  11. # This is a shell archive, meaning:
  12. # 1. Remove everything above the #! /bin/sh line.
  13. # 2. Save the resulting text in a file.
  14. # 3. Execute the file with /bin/sh (not csh) to create the files:
  15. #    confprnt.c
  16. #    confrots.c
  17. #    confrw.c
  18. export PATH; PATH=/bin:$PATH
  19. if test -f 'confprnt.c'
  20. then
  21.     echo shar: will not over-write existing file "'confprnt.c'"
  22. else
  23. cat << \SHAR_EOF > 'confprnt.c'
  24. /*
  25.  *    conf - An interactive multi-user chat program.
  26.  *
  27.  *    conf Copyright (c) 1986, 1987 by Keith Gabryelski
  28.  *
  29.  *    Conf is quasi-public domain software; it may be used and copied
  30.  *    freely and may be modified to suit the indivuals needs as long
  31.  *    as:
  32.  *
  33.  *    [1] It is not sold.
  34.  *    [2] It is not made part of any licensed product.
  35.  *    [3] This header and others like it are not modified or removed.
  36.  *    [4] You allow others to use and copy without charge.
  37.  *    
  38.  *    without expressed written permission from the original
  39.  *    author (Keith Gabryelski).
  40.  *
  41.  */
  42.  
  43. #include "conf.h"
  44.  
  45. jmp_buf glenv, cvenv;
  46.  
  47. #define    BACKCHAR() {if (expand8bit && !isascii(*(lp-1)))         \
  48.             (void)fputs("\b \b", stdout);              \
  49.             if (expandctrl && iscntrl(toascii(*(lp-1)))) \
  50.             (void)fputs("\b \b", stdout);              \
  51.             (void)fputs("\b \b", stdout); --lp;}
  52.  
  53. unsigned linelen, col = 0;
  54.  
  55. my_intr(sig)
  56. int sig;
  57. {
  58.     longjmp(glenv, sig);
  59. }
  60.  
  61. save_intr(sig)
  62. int sig;
  63. {
  64.     longjmp(cvenv, sig);
  65. }
  66.  
  67. fputchar(c)
  68. int c;
  69. {
  70.     (void)putchar(c);
  71. }
  72.  
  73. printmess(stream, constr, usr, tty, mess, length)
  74. char *constr, *usr, *tty, *mess;
  75. unsigned length;
  76. FILE *stream;
  77. {
  78.     register char *ptr = constr;
  79.     register int c;
  80.  
  81.     while (c = *ptr++)
  82.     {
  83.     switch(c)
  84.     {
  85.         case '%':
  86.         switch(c = *ptr++)
  87.         {
  88.             case 'T':
  89.             visprnt(cuser.cu_tty, stream);
  90.             break;
  91.  
  92.             case 't':
  93.             visprnt(tty, stream);
  94.             break;
  95.  
  96.             case 'N':
  97.             visprnt(cuser.cu_cname, stream);
  98.             break;
  99.  
  100.             case 'n':
  101.             visprnt(usr, stream);
  102.             break;
  103.  
  104.             case 'm':
  105.             messptr(mess, stream, length);
  106.             break;
  107.  
  108.             case '\0':
  109.             (void)putc('%', stream);
  110.             --ptr;
  111.             break;
  112.  
  113.             default:
  114.             (void)putc('%', stream);
  115.             case '%':
  116.             (void)putc(c, stream);
  117.             break;
  118.         }
  119.         break;
  120.  
  121.         default:
  122.         (void)putc(c, stream);
  123.         break;
  124.     }
  125.     }
  126.     (void)fflush(stream);
  127. }
  128.  
  129. messptr(mess, stream, length)
  130. char *mess;
  131. unsigned length;
  132. FILE *stream;
  133. {
  134.     register char *ptr = mess;
  135.  
  136.     while (length--)
  137.     dispchar(*ptr++, stream, NOVIS);
  138.  
  139.     (void)fflush(stream);
  140. }
  141.  
  142. visprnt(mess, stream)
  143. char *mess;
  144. FILE *stream;
  145. {
  146.     register char *ptr = mess;
  147.  
  148.     while (*ptr)
  149.     dispchar(*ptr++, stream, VIS);
  150.  
  151.     (void)fflush(stream);
  152. }
  153.  
  154. vislen(mess)
  155. register char *mess;
  156. {
  157.     register int length = 0;
  158.  
  159.     while (*mess)
  160.     {
  161.     if (!isascii(*mess) && expand8bit)
  162.         length += 2;
  163.     if (iscntrl(*mess) && expandctrl)
  164.         ++length;
  165.     ++length;
  166.     ++mess;
  167.     }
  168.  
  169.     return length;
  170. }
  171.  
  172. dispchar(c, stream, flag)
  173. int c;
  174. FILE *stream;
  175. int flag;
  176. {
  177.     int wasmeta = FALSE;
  178.  
  179.     if (!isascii(c) && !expand8bit)
  180.     {
  181.     (void)putc(c, stream);
  182.     return;
  183.     }
  184.  
  185.     if (!isascii(c))
  186.     {
  187.     (void)putc('~', stream);
  188.     c = toascii(c);
  189.     wasmeta = TRUE;
  190.     }
  191.  
  192.     if (iscntrl(c) && expandctrl)
  193.     {
  194.     switch (c)
  195.     {
  196.         case DEL:
  197.         (void)fputs("^?", stream);
  198.         break;
  199.  
  200.         case '\n':
  201.         case TAB:
  202.         if (!wasmeta && !(flag&VIS))
  203.         {
  204.             (void)putc(c, stream);
  205.             break;
  206.         }
  207.  
  208.         default:
  209.         (void)putc('^', stream);
  210.         (void)putc(c|'@', stream);
  211.         break;
  212.     }
  213.     }
  214.     else
  215.     (void)putc(c, stream);
  216. }
  217.  
  218. char *
  219. getline()
  220. {
  221.     int c;
  222.     char *line = mymalloc(PAGESIZ);
  223.     int tmplen, len = PAGESIZ;
  224.     char *lp = line;
  225.  
  226.     if (c = setjmp(glenv))
  227.     {
  228.     (void)alarm(0);
  229.     (void)signal(SIGALRM, my_intr);
  230.     (void)signal(SIGINT, SIG_IGN);
  231.  
  232.     switch(c)
  233.     {
  234.         case SIGINT:
  235.         dispchar(ichar, stdout, NOVIS);
  236.         (void)putchar('\n');
  237.         break;
  238.     }
  239.  
  240.     free(line);
  241.     return NULL;
  242.     }
  243.  
  244.     (void)signal(SIGALRM, my_intr);
  245.     (void)signal(SIGINT, my_intr);
  246.  
  247.     (void)alarm(1);
  248.     read(0, lp, 1);
  249.     (void)alarm(0);
  250.  
  251.     do
  252.     {
  253.     if (lineinput) switch(*lp)
  254.     {
  255.         case CR:
  256.         case LF:
  257.         if (lp == line)
  258.         {
  259.             free(line);
  260.             return NULL;
  261.         }
  262.         *lp = '\0';
  263.         linelen = lp - line;
  264.         return line;
  265.  
  266.         default:
  267.         lp++;
  268.             break;
  269.     }
  270.     else switch(*lp)
  271.     {
  272.         case BS:
  273.         case DEL:
  274.         if (lp > line)
  275.             {BACKCHAR();}
  276.         else
  277.             (void)putchar(BELL);
  278.  
  279.         (void)fflush(stdout);
  280.  
  281.         if (lp == line)
  282.         {
  283.             free(line);
  284.             return NULL;
  285.             }
  286.         break;
  287.  
  288.         case CR:
  289.         case LF:
  290.         (void)putchar('\n');
  291.  
  292.         if (lp == line)
  293.         {
  294.             free(line);
  295.             return NULL;
  296.         }
  297.         *lp = '\0';
  298.         linelen = lp - line;
  299.         return line;
  300.  
  301.         case CTRL(L):
  302. #ifdef    USE_TERMCAP
  303.         tputs(cls, lines, fputchar);
  304. #endif    USE_TERMCAP
  305. #ifndef    USE_TERMCAP
  306.         (void)fputs(cls, stdout);
  307. #endif    USE_TERMCAP
  308.  
  309.         messptr(line, stdout, (unsigned)(lp-line));
  310.  
  311.         if (lp == line)
  312.         {
  313.             free(line);
  314.             return NULL;
  315.         }
  316.         break;
  317.  
  318.         case CTRL(R):
  319.         *lp = '\0';
  320.         (void)puts("^R");
  321.  
  322.         messptr(line, stdout, (unsigned)(lp-line));
  323.  
  324.         if (lp == line)
  325.         {
  326.             free(line);
  327.             return NULL;
  328.         }
  329.         break;
  330.  
  331.         case CTRL(U):
  332.         while (lp > line)
  333.             BACKCHAR();
  334.  
  335.         (void)fflush(stdout);
  336.         free(line);
  337.         return NULL;
  338.  
  339.         case CTRL(V):
  340.         if (c = setjmp(cvenv))
  341.         {
  342.             switch(c)
  343.             {
  344.             case SIGINT:
  345.                 *lp = ichar;
  346.                 break;
  347.  
  348.             case SIGQUIT:
  349.                 *lp = qchar;
  350.                 break;
  351.             }
  352.         }
  353.         else
  354.         {
  355.             (void)signal(SIGINT, save_intr);
  356.             (void)signal(SIGQUIT, save_intr);
  357.  
  358.             if (read(0, lp, 1) != 1)
  359.             {
  360.             free(line);        /* some sort of read error */
  361.             return NULL;
  362.             }
  363.         }
  364.  
  365.         (void)signal(SIGINT, my_intr);
  366.         (void)signal(SIGQUIT, fatal);
  367.         dispchar(*lp++, stdout, NOVIS);
  368.         (void)fflush(stdout);
  369.         break;
  370.  
  371.         case CTRL(W):
  372.         while ((lp > line) && isspace(*(lp-1)))
  373.             BACKCHAR();   /* ditch the post word white space */
  374.  
  375.         while ((lp > line) && !isspace(*(lp-1)))
  376.             BACKCHAR(); /* someday a cool worderizer */
  377.  
  378.         (void)fflush(stdout);
  379.  
  380.         if (lp == line)
  381.         {
  382.             free(line);
  383.             return NULL;
  384.         }
  385.         break;
  386.  
  387.         case CTRL(D):    /* default must follow this case */
  388.         if (lp == line)
  389.         {
  390.             (void)puts(":quit");
  391.             nice_exit(0);
  392.         }
  393.                 /* if not first character, do default: */
  394.         default:
  395.         dispchar(*lp++, stdout, NOVIS);
  396.         (void)fflush(stdout);
  397.             break;
  398.     }
  399.  
  400.     if ((tmplen = lp - line) >= len )
  401.     {
  402.         line = myrealloc(line, (unsigned)(len += PAGESIZ));
  403.         lp = line + tmplen;
  404.     }
  405.  
  406.     } while(read(0, lp, 1));
  407.  
  408.     free(line);
  409.     return NULL;    /* error while reading -- punt */
  410. }
  411.  
  412. colprnt(word, pad)
  413. char *word;
  414. int pad;
  415. {
  416.     if (col+pad > columns-1)
  417.     {
  418.     if (!columns)
  419.     {
  420.         visprnt(word, stdout);
  421.         (void)putchar('\n');
  422.     }
  423.     else
  424.     {
  425.         col = pad;
  426.         (void)putchar('\n');
  427.         visprnt(word, stdout);
  428.         (void)printf("%-*s", pad-vislen(word), " ");
  429.     }
  430.     }
  431.     else
  432.     {
  433.     col += pad;
  434.     visprnt(word, stdout);
  435.     (void)printf("%-*s", pad-vislen(word), " ");
  436.     }
  437. }
  438.  
  439. terpri()
  440. {
  441.     if (col)
  442.     (void)putchar('\n');
  443.     col = 0;
  444. }
  445. SHAR_EOF
  446. fi # end of overwriting check
  447. if test -f 'confrots.c'
  448. then
  449.     echo shar: will not over-write existing file "'confrots.c'"
  450. else
  451. cat << \SHAR_EOF > 'confrots.c'
  452. /*
  453.  *    conf - An interactive multi-user chat program.
  454.  *
  455.  *    conf Copyright (c) 1986, 1987 by Keith Gabryelski
  456.  *
  457.  *    Conf is quasi-public domain software; it may be used and copied
  458.  *    freely and may be modified to suit the indivuals needs as long
  459.  *    as:
  460.  *
  461.  *    [1] It is not sold.
  462.  *    [2] It is not made part of any licensed product.
  463.  *    [3] This header and others like it are not modified or removed.
  464.  *    [4] You allow others to use and copy without charge.
  465.  *    
  466.  *    without expressed written permission from the original
  467.  *    author (Keith Gabryelski).
  468.  *
  469.  */
  470.  
  471. #include "conf.h"
  472.  
  473. #ifdef    MYCRYPT
  474. char *ourkey;
  475. #endif    MYCRYPT
  476.  
  477. int do_who(), do_record(), do_to(), moby_hlp(), wee_hlp();
  478. int shell_it(), do_shout(), do_send(), do_reply(), do_from();
  479. int do_set(), rms(), do_shell(), do_cls(), echo_fn();
  480.  
  481. FILE *hfp;
  482.  
  483. static struct
  484.     {
  485.     char *fn_name;
  486.     int (*fn_func)();
  487.     int fn_arg;
  488.     }
  489.     cmdtab[] =
  490.     {
  491.     { "?", wee_hlp, },
  492.     { "cls", do_cls, },
  493.     { "echo", echo_fn, },
  494.     { "exit", nice_exit, 0, },
  495.     { "from", do_from, },
  496.     { "help", moby_hlp, },
  497.     { "quit", nice_exit, 0, },
  498.     { "record", do_record, },
  499.     { "reply", do_reply, },
  500.     { "ring", do_ring, },
  501.     { "rms", rms, },
  502.     { "send", do_send, },
  503.     { "set", do_set, },
  504.     { "shell", do_shell, },
  505.     { "shout", do_shout, },
  506.     { "to", do_to, },
  507.     { "version", version, TRUE, },
  508.     { "who", do_who, 0, },
  509.     { NULL, }
  510.     }, *cmdptr;
  511.  
  512. intpret(line)
  513. char *line;
  514. {
  515.     cmdptr = cmdtab;
  516.     line = parsestr(line, (int)linelen, NEXTWORD);
  517.  
  518.     if (line != NULL)
  519.     {
  520.     for (cmdptr = cmdtab; cmdptr->fn_name != NULL; cmdptr++)
  521.     {
  522.         if (!strcmp(cmdptr->fn_name, line))
  523.         return (*cmdptr->fn_func)(cmdptr->fn_arg);
  524.     }
  525.  
  526.     if (confing)
  527.     {
  528.         (void)fputs("Invalid command: \"", stdout);
  529.         visprnt(line, stdout);
  530.         (void)puts("\"  :? for list");
  531.     }
  532.     }
  533.     return FALSE;
  534. }
  535.  
  536. do_to()
  537. {
  538.     char *ptr, tmp[20];
  539.     int ln;
  540.  
  541.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) != NULL)
  542.     {
  543.     if (((ln = atoi(ptr)) < 1) || (ln > MAXCONFLINES))
  544.     {
  545.         if (confing)
  546.         (void) printf("Invalid line number: %d.\n", ln);
  547.  
  548.         return FALSE;
  549.     }
  550.     else
  551.     {
  552.         if (confing)
  553.         {
  554.         if (cuser.cu_line == ln)
  555.             (void) printf("Already on line %d.\n", ln);
  556.         else
  557.         {
  558.             (void) sprintf(tmp, "To line %d", ln);
  559.             write_log(INFORM, tmp, (char *)NULL, (unsigned)0,
  560.                 (unsigned)strlen(tmp));
  561.  
  562.             (void) sprintf(tmp, "From line %d", cuser.cu_line);
  563.             clog.f_line = cuser.cu_line = ln;
  564.  
  565.             (void) printf("Now on line %d.\n", ln);
  566.  
  567.             write_usr();
  568.  
  569.             write_log(INFORM, tmp, (char *)NULL, (unsigned)0,
  570.                 (unsigned)strlen(tmp));
  571.  
  572.             if (cuser.cu_flags&USER_RECORD)
  573.             write_log(INFORM, "Recording", (char *)NULL,
  574.                     (unsigned)0, (unsigned)strlen("Recording"));
  575.         }
  576.         }
  577.         else
  578.         {
  579.         clog.f_line = cuser.cu_line = ln;
  580.         return TRUE;
  581.         }
  582.     }
  583.     }
  584.     else
  585.     if (confing)
  586.         (void) printf("On line %d.\n", cuser.cu_line);
  587.     else
  588.         return FALSE;
  589.  
  590.     return TRUE;
  591. }
  592.  
  593. do_from()
  594. {
  595.     char *ptr;
  596.     int fd;
  597.  
  598.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  599.     {
  600.     (void)puts("No file name given.");
  601.     return FALSE;
  602.     }
  603.  
  604.     if ((fd = open(ptr, O_RDONLY)) < 0)
  605.     {
  606.     (void) printf("Couldn't open %s (%s)\n",ptr, puterr(errno));
  607.     return FALSE;
  608.     }
  609.     else
  610.     {
  611.     char *buf;
  612.     unsigned fsiz;
  613.     struct stat stbuf;
  614.  
  615.     if (fstat(fd, &stbuf) < 0)
  616.     {
  617.         (void) printf("Coundn't stat %s (%s); aborting.\n", ptr,
  618.         puterr(errno));
  619.         (void) close(fd);
  620.         return FALSE;
  621.     }
  622.     else
  623.     {
  624.         fsiz = (unsigned int)stbuf.st_size;
  625.         buf = mymalloc(fsiz);
  626.  
  627.         read(fd, buf, fsiz);
  628.  
  629.         write_log(NORMAL, buf, (char *)NULL, 0, fsiz);
  630.         free(buf);
  631.         (void)close(fd);
  632.     }
  633.     }
  634.     return TRUE;
  635. }
  636.  
  637.  
  638. do_who(line)
  639. int line;
  640. {
  641.     int namelen, ttylen, users;
  642.     char *ptr;
  643.     struct whostr **wholist, **whoptr;
  644.  
  645.     if (!confing)
  646.     if ((usr_fd = open(CONFUSERS, O_RDONLY)) < 0)
  647.     {
  648.         if (errno == ENOENT) /* Brian ENOENT */
  649.         (void)fprintf(stderr,"No users on %s.\n", progname);
  650.         else
  651.         (void)fprintf(stderr,"%s: couldn't open %s (%s)\n", progname,
  652.             CONFUSERS, puterr(errno));
  653.         return (-1);
  654.     }
  655.  
  656.     wholist = (struct whostr **)mymalloc(0);
  657.  
  658.     if (confing && !line)
  659.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) != NULL)
  660.         line = atoi(ptr);
  661.  
  662.     if (line > MAXCONFLINES)
  663.     line = 0;
  664.  
  665.     users = 0;
  666.     namelen = strlen("Name");
  667.     ttylen = strlen("Tty");
  668.     (void) lseek(usr_fd, 0L, 0);
  669.     while(read(usr_fd, (char *)&tuser, (unsigned)sizeof(struct cusrfil)))
  670.     {
  671.     if ((tuser.cu_flags != USER_OFF) &&
  672.         (!line || (line && (tuser.cu_line == line))))
  673.     {
  674.         wholist = (struct whostr **)myrealloc(wholist,
  675.                 sizeof (struct whostr **)*(users+1));
  676.         whoptr = (struct whostr **)&wholist[users++];
  677.         *whoptr = (struct whostr *)mymalloc(sizeof (struct whostr));
  678.         (void) strcpy((*whoptr)->name, tuser.cu_cname);
  679.         (void) strcpy((*whoptr)->tty, tuser.cu_tty);
  680.         (*whoptr)->line = tuser.cu_line;
  681.         (*whoptr)->flags = tuser.cu_flags;
  682.  
  683.         if (strlen((*whoptr)->name) > namelen)
  684.         namelen = strlen((*whoptr)->name);
  685.  
  686.         if (strlen((*whoptr)->tty) > ttylen)
  687.         ttylen = strlen((*whoptr)->tty);
  688.     }
  689.  
  690.     }
  691.  
  692.     wholist = (struct whostr **)myrealloc(wholist,
  693.             sizeof (struct whostr **)*(users+1));
  694.     wholist[users] = (struct whostr *)NULL;
  695.  
  696.     if (!users)
  697.     {
  698.     if (line)
  699.         (void) printf("No users on line %d.\n", line);
  700.     else
  701.         (void) printf("No users on %s.\n", progname);
  702.     }
  703.     else
  704.     {
  705.     char prefix;
  706.     namelen += TABAGE;
  707.     ttylen += TABAGE;
  708.     whoptr = wholist;
  709.  
  710.     if (line)
  711.     {
  712.         (void) printf(" %-*s%-*s\n", namelen, "Name", ttylen, "Tty");
  713.         while (*whoptr != (struct whostr *)NULL)
  714.         {
  715.         if ((*whoptr)->flags&USER_RECORD)
  716.             prefix = '*';
  717.         else
  718.             prefix = ' ';
  719.  
  720.         (void) printf("%c%-*s%-*s\n", prefix, namelen, (*whoptr)->name,
  721.             ttylen, (*whoptr)->tty);
  722.         whoptr++;
  723.         }
  724.     }
  725.     else
  726.     {
  727.         (void) printf(" %-*s%-*s%s\n", namelen, "Name", ttylen, "Tty", "Line");
  728.         while (*whoptr != (struct whostr *)NULL)
  729.         {
  730.         if ((*whoptr)->flags&USER_RECORD)
  731.             prefix = '*';
  732.         else
  733.             prefix = ' ';
  734.  
  735.         (void) printf("%c%-*s%-*s%d\n",prefix,namelen,(*whoptr)->name,
  736.             ttylen, (*whoptr)->tty, (*whoptr)->line);
  737.         whoptr++;
  738.         }
  739.     }
  740.     whoptr = wholist;
  741.     while (*whoptr != (struct whostr *)NULL)
  742.         free(*whoptr++);
  743.     }
  744.     free(wholist);
  745.  
  746.     if (!confing)
  747.     (void) close(usr_fd);
  748.  
  749.     return TRUE;
  750. }
  751.  
  752. do_record()
  753. {
  754.     char *ptr;
  755.  
  756. /* check to see if filename will screw log/user file */
  757.  
  758.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  759.     {
  760.     if (cuser.cu_flags&USER_RECORD)
  761.     {
  762.         (void)fclose(rec_fp);
  763.         cuser.cu_flags &= ~USER_RECORD;
  764.         write_usr();
  765.         if (confing)
  766.         {
  767.         write_log(INFORM, "Recording OFF", (char *)NULL, (unsigned)0,
  768.             (unsigned)strlen("Recording OFF"));
  769.         (void)fputs("Recording OFF.\n", stdout);
  770.         }
  771.         return FALSE;
  772.     }
  773.     else
  774.         ptr = recfile;
  775.     } 
  776.  
  777.     if (cuser.cu_flags&USER_RECORD)
  778.     (void) fclose(rec_fp);
  779.  
  780.     if ((rec_fp = fopen(ptr, "a")) == (FILE *)NULL)
  781.     {
  782.     (void) fputs("Couldn't open ", stdout);
  783.     messptr(ptr, stdout, (unsigned)strlen(ptr));
  784.     (void) printf(" (%s).\n", puterr(errno));
  785.  
  786.     if (cuser.cu_flags&USER_RECORD)
  787.     {
  788.         cuser.cu_flags &= ~USER_RECORD;
  789.         if (confing)
  790.         {
  791.         write_log(INFORM, "Recording OFF", (char *)NULL, (unsigned)0,
  792.             (unsigned)strlen("Recording OFF"));
  793.         (void) printf("Recording OFF\n");
  794.         }
  795.     }
  796.     }
  797.     else
  798.     {
  799.     if (confing)
  800.     {
  801.         if (cuser.cu_flags&USER_RECORD)
  802.         (void)fputs("Changing record file to ", stdout);
  803.         else
  804.         (void)fputs("Recording to file ", stdout);
  805.  
  806.         (void) printf("%s.\n", ptr);
  807.         write_log(INFORM, "Recording ON", (char *)NULL, (unsigned)0,
  808.         (unsigned)strlen("Recording ON"));
  809.     }
  810.  
  811.     cuser.cu_flags |= USER_RECORD;
  812.     }
  813.  
  814.     write_usr();
  815.     return TRUE;
  816. }
  817.  
  818. wee_hlp()
  819. {
  820.     char *ptr;
  821.  
  822.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  823.     {
  824.     int tmp, len=0;
  825.     cmdptr = cmdtab;
  826.  
  827.     for (cmdptr = cmdtab; cmdptr->fn_name != NULL; cmdptr++)
  828.         if ((tmp = strlen(cmdptr->fn_name)) > len)
  829.         len = tmp;
  830.     
  831.     len += TABAGE;
  832.  
  833.     for (cmdptr = cmdtab; cmdptr->fn_name != NULL; cmdptr++)
  834.         colprnt(cmdptr->fn_name, len);
  835.  
  836.     terpri();
  837.  
  838.     return TRUE;
  839.     }
  840.     else
  841.     {
  842.     char *word;
  843.     int c;
  844.  
  845.     if ((hfp = fopen(CONFHELP, "r")) == (FILE *)NULL)
  846.         (void)printf("Couldn't open help file %s (%s).\n",
  847.         CONFHELP, puterr(errno));
  848.     else
  849.     {
  850.         while ((word = getword()) != NULL)
  851.         if (!strcmp(word+1, ptr))
  852.         {
  853.             (void)fputs(word, stdout);
  854.             while(((c = getc(hfp)) != EOF) && (c != '\n'))
  855.             (void)putchar(c);
  856.  
  857.             (void)putchar('\n');
  858.             (void)fclose(hfp);
  859.             return TRUE;
  860.         }
  861.  
  862.         (void) printf("Command not found: %s\n", ptr);
  863.     }
  864.     }
  865.     (void)fclose(hfp);
  866.     return FALSE;
  867. }
  868.  
  869. moby_hlp()
  870. {
  871.     int c, lastnl;
  872.     char *ptr, *word;
  873.  
  874.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  875.     {
  876.     ptr = mymalloc((unsigned int)(strlen(pager)+1+strlen(CONFHELP) + 1));
  877.     (void)strcpy(ptr, pager);
  878.     (void)strcat(ptr, " ");
  879.     (void)strcat(ptr, CONFHELP);
  880.  
  881.     (void) shell_it(ptr);
  882.     free(ptr);
  883.     return TRUE;
  884.     }
  885.     else
  886.     {
  887.     if ((hfp = fopen(CONFHELP, "r")) == (FILE *)NULL)
  888.         (void)printf("Couldn't open help file %s (%s).\n",
  889.         CONFHELP, puterr(errno));
  890.     else
  891.     {
  892.         while ((word = getword()) != NULL)
  893.         if (!strcmp(word+1, ptr))
  894.         {
  895.             (void)fputs(word, stdout);
  896.             lastnl = FALSE;
  897.             while((c = getc(hfp)) != EOF)
  898.             if (c == '\n')
  899.             {
  900.                 if (lastnl)
  901.                 {
  902.                 (void)fclose(hfp);
  903.                 return TRUE;
  904.                 }
  905.  
  906.                 (void)putchar(c);
  907.                 lastnl = TRUE;
  908.             }
  909.             else
  910.             {
  911.                 lastnl = FALSE;
  912.                 (void)putchar(c);
  913.             }
  914.         }
  915.  
  916.         (void)printf("Command not found: %s\n", ptr);
  917.         (void)fclose(hfp);
  918.     }
  919.     }
  920.     return FALSE;
  921. }
  922.  
  923. char *
  924. getword()
  925. {
  926.     int c;
  927.     static char buf[100];
  928.     char *bp = buf;
  929.  
  930.     forever
  931.     {
  932.     while (((c = getc(hfp)) != '\n') && (c != EOF)) ;
  933.  
  934.     if (c == EOF)
  935.         return NULL;
  936.  
  937.     if ((c = getc(hfp)) != ':')
  938.         (void)ungetc(c, hfp);
  939.     else
  940.     {
  941.         do
  942.         {
  943.         *bp++ = c;
  944.         } while (!isspace((c = getc(hfp))));
  945.  
  946.         (void)ungetc(c, hfp);
  947.         *bp = '\0';
  948.         return buf;
  949.     }
  950.     }
  951. }
  952.  
  953. do_shell()
  954. {
  955.     if (shell_it(shell) <0)
  956.     (void) puts("!Error");
  957.     else
  958.     (void) puts("!");
  959. }
  960.  
  961. keep_shell(line)
  962. char *line;
  963. {
  964.     static char *lastcmd;
  965.  
  966.     if (*line == '!')
  967.     {
  968.     if (lastcmd == NULL)
  969.     {
  970.         (void)puts("No previous command.");
  971.     }
  972.     else
  973.     {
  974.         lastcmd = myrealloc(lastcmd, (unsigned)(strlen(lastcmd) + strlen(line+1) +1));
  975.         (void)strcat(lastcmd, line+1);
  976.     }
  977.     }
  978.     else
  979.     {
  980.     lastcmd = myrealloc(lastcmd, (unsigned)(strlen(line) + 1));
  981.     (void)strcpy(lastcmd, line);
  982.     }
  983.  
  984.     if (shell_it(lastcmd) <0)
  985.     (void) puts("!Error");
  986.     else
  987.     (void)puts("!");
  988. }
  989.  
  990. shell_it(line)
  991. char *line;
  992. {
  993.     int status;
  994. #ifdef    SYSV
  995.     (void) ioctl(0, TCSETAW, &saveterm);
  996. #endif    SYSV
  997.  
  998. #ifdef    BSD
  999.     int tmpflags;
  1000.  
  1001.     tmpflags = ktty.sg_flags;
  1002.     ktty.sg_flags = ttyflags;
  1003.     stty(0, &ktty);
  1004. #endif    BSD
  1005.  
  1006.     (void)signal(SIGINT, SIG_DFL);
  1007.  
  1008.     status = system(line);
  1009.  
  1010.     (void)signal(SIGINT, SIG_IGN);
  1011.  
  1012. #ifdef    SYSV
  1013.     (void) ioctl(0, TCSETAW, &term);
  1014. #endif    SYSV
  1015.  
  1016. #ifdef    BSD
  1017.     ktty.sg_flags = tmpflags;
  1018.     stty(0, &ktty);
  1019. #endif    BSD
  1020.  
  1021.     return status;
  1022. }
  1023.  
  1024. set_pass()
  1025. {
  1026.     char *ptr;
  1027.  
  1028.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  1029.     {
  1030.     cpystr(curkey, pubkey, 8);
  1031.     makepass(curkey, curblock, curpass);
  1032.     if (confing)
  1033.         (void)fputs("Password reset.\n", stdout);
  1034.     }
  1035.     else
  1036.     {
  1037.     zbuf(curkey, 8);
  1038.     (void)strncpy(curkey, ptr, 8);
  1039.     makepass(curkey, curblock, curpass);
  1040.     if (confing)
  1041.         (void)fputs("Password set.\n", stdout);
  1042.     }
  1043.  
  1044.     return TRUE;
  1045. }
  1046.  
  1047. makepass(string, array, pass)
  1048. char *string, *array, *pass;
  1049. {
  1050.     char tmparr[64];
  1051.     char *tarrp = tmparr;
  1052.  
  1053.     register int i;
  1054.  
  1055.     passblock(string, array);
  1056.  
  1057.     for (i=0; i < 64; ++i)
  1058.        *tarrp++ = *array++; 
  1059.  
  1060.     setkey(pubblock);
  1061.  
  1062. #ifdef DEBUG2
  1063.     printbuf(tmparr);    
  1064.     (void)fputs("\n", stdout);
  1065. #endif DEBUG2
  1066.  
  1067.     encrypt(tmparr, 0);            /* encrypt buffer */
  1068.  
  1069. #ifdef DEBUG2
  1070.     printbuf(tmparr);    
  1071.     (void)fputs("\n", stdout);
  1072.  
  1073.     setkey(pubblock);
  1074.  
  1075.     encrypt(tmparr, 1);            /* decrypt buffer */
  1076.  
  1077.     printbuf(tmparr);    
  1078.     (void)fputs("\n", stdout);
  1079. #endif DEBUG2
  1080.  
  1081.     unmakeblock(pass, tmparr);
  1082.  
  1083. #ifdef DEBUG2
  1084.     (void)printf("%s\n", pass);
  1085. #endif DEBUG2
  1086. }
  1087.  
  1088. #ifdef DEBUG2
  1089. printbuf(buff)
  1090. char *buff;
  1091. {
  1092.     int i;
  1093.  
  1094.     for (i=0; i < 64; ++i)
  1095.     (void)printf("%x", *buff++);
  1096. }
  1097. #endif DEBUG2
  1098.  
  1099. passblock(string, array)
  1100. char *string, *array;
  1101. {
  1102.     register unsigned char c;
  1103.     register int i, x;
  1104.  
  1105.     for (i=0; i < 8; ++i)
  1106.     {
  1107.     c = *string;
  1108.     if (c) ++string;
  1109.     
  1110.     for (x=0; x < 8; ++x, c >>= 1)
  1111.         *array++ = c&1;
  1112.     }
  1113. }
  1114.  
  1115. makeblock(string, array)
  1116. char *string, *array;
  1117. {
  1118.     register unsigned char c;
  1119.     register int i, x;
  1120.  
  1121.     for (i=0; i < 8; ++i)
  1122.     {
  1123.     c = *string++;
  1124.     for (x=0; x < 8; ++x, c >>= 1)
  1125.         *array++ = c&1;
  1126.     }
  1127. }
  1128.  
  1129. unmakeblock(pass, array)
  1130. char *pass, *array;
  1131. {
  1132.     register int x, i;
  1133.     register unsigned char c;
  1134.  
  1135.     for (i=0; i < 8; ++i)
  1136.     {
  1137.     c = 0;
  1138.     for (x=0; x < 8; ++x)
  1139.     {
  1140.         c >>= 1;
  1141.         if (*array++)
  1142.         c |= 0x80;
  1143.     }
  1144.     *pass++ = c;
  1145.     }
  1146.  
  1147. }
  1148.  
  1149. enccpy(to, from, length, flag)
  1150. char *to, *from;
  1151. unsigned int length;
  1152. int flag;
  1153. {
  1154.     char block[64];
  1155.     int i;
  1156.  
  1157.     for (i=0; i < length; ++i)
  1158.     {
  1159.     makeblock(from, block);
  1160.  
  1161.     encrypt(block, flag);
  1162.  
  1163.     unmakeblock(to, block);
  1164.     from += 8; to += 8;
  1165.     }
  1166. }
  1167.  
  1168. #ifdef    MYCRYPT
  1169. setkey(key)
  1170. char *key;
  1171. {
  1172.     ourkey = key;
  1173.     return;
  1174. }
  1175.  
  1176. encrypt(ptr, flag)
  1177. char *ptr;
  1178. int flag;
  1179. {
  1180.     register char *okp = ourkey;
  1181.     register int i;
  1182.  
  1183.     for (i= flag&0; i < 64; ++i)
  1184.     *ptr++ ^= *okp++;
  1185. }
  1186. #endif    MYCRYPT
  1187.  
  1188. do_shout()
  1189. {
  1190.     char *ptr;
  1191.  
  1192.     if (!confing)
  1193.     return FALSE;
  1194.  
  1195.     ptr = parsestr((char *)NULL, 0, THEREST);
  1196.  
  1197.     write_log(SHOUT, ptr, (char *)NULL, (unsigned)0, wordlen);
  1198.     return TRUE;
  1199. }
  1200.  
  1201. do_reply()
  1202. {
  1203.     char *ptr;
  1204.  
  1205.     if (!confing)
  1206.     return FALSE;
  1207.  
  1208.     if (*replytty == '\0')
  1209.     (void)puts("No one to reply to.");
  1210.     else
  1211.     {
  1212.     if ((ptr = parsestr((char *)NULL, 0, THEREST)) == NULL)
  1213.         (void)printf("Last send was from %s (%s).\n", replyname, replytty);
  1214.     else
  1215.         write_log(SEND, ptr, replytty, (unsigned)(strlen(replytty)+1),
  1216.             wordlen);
  1217.     }
  1218.     return TRUE;
  1219. }
  1220.  
  1221. do_send()
  1222. {
  1223.     char *to, *temp, *lastnam, *cp;
  1224.     int found;
  1225.     unsigned int tolen = 0;
  1226.     unsigned int tp;
  1227.  
  1228.     if (!confing)
  1229.     return FALSE;
  1230.  
  1231.     if ((cp = parsestr((char *)NULL, 0, THEREST)) == NULL)
  1232.     {
  1233.     (void)puts("No parameters given to send, usage :send usr,/line,:tty,... message");
  1234.     return FALSE;
  1235.     }
  1236.  
  1237.     if (tolen == 0)
  1238.     to = mymalloc(tolen = PAGESIZ);
  1239.  
  1240.     temp = to;
  1241.  
  1242.     do
  1243.     {
  1244.     while (wordlen && isspace(*cp))
  1245.     {
  1246.         --wordlen;
  1247.         cp++;
  1248.     }
  1249.  
  1250.     lastnam = temp;
  1251.     while (wordlen && (isalnum(*cp) || ((lastnam == temp) && (strchr("/:", *cp)))))
  1252.     {
  1253.         if (temp - to + 2 >= tolen)
  1254.         {
  1255.         tp = temp - to;
  1256.         to = myrealloc(to, tolen += PAGESIZ);
  1257.         temp = to+tp;
  1258.         }
  1259.  
  1260.         --wordlen;
  1261.         *temp++ = *cp++;
  1262.     }
  1263.     *temp++ = '\0';
  1264.  
  1265.     /* check here for validity of send parameter */
  1266.  
  1267.     (void)lseek(usr_fd, 0L, 0);
  1268.  
  1269. #ifdef    SYSV
  1270.     lockf(usr_fd, F_LOCK, 0L);    /* lock user file */
  1271. #endif    SYSV
  1272.  
  1273. #ifdef    BSD
  1274.     flock(usr_fd, LOCK_EX);
  1275. #endif    BSD
  1276.  
  1277.     found = FALSE;
  1278.     switch(*lastnam)
  1279.     {
  1280.     int num;
  1281.  
  1282.     case '/':
  1283.         num = atoi(lastnam+1);
  1284.         if ((num < 1) || (num > MAXCONFLINES))
  1285.         {
  1286.         (void)printf("Invalid conference line number: %s\n", lastnam+1);
  1287.         temp = lastnam;
  1288.         break;
  1289.         }
  1290.  
  1291.         while (read(usr_fd, (char *)&tuser, sizeof(struct cusrfil)) ==
  1292.             sizeof(struct cusrfil))
  1293.         if ((tuser.cu_flags == USER_ON) && (tuser.cu_line == num))
  1294.             found = TRUE;
  1295.  
  1296.         if (!found)
  1297.         {
  1298.         (void)printf("No one is on conference line %d\n", num);
  1299.         temp = lastnam;
  1300.         }
  1301.         break;
  1302.  
  1303.     case ':':
  1304.         while (read(usr_fd, (char *)&tuser, sizeof(struct cusrfil)) ==
  1305.             sizeof(struct cusrfil))
  1306.         if ((tuser.cu_flags == USER_ON) && !strcmp(tuser.cu_tty, lastnam+1))
  1307.             found = TRUE;
  1308.  
  1309.         if (!found)
  1310.         {
  1311.         (void)printf("No user on %s\n", lastnam+1);
  1312.         temp = lastnam;
  1313.         }
  1314.         break;
  1315.  
  1316.     default:
  1317.         while (read(usr_fd, (char *)&tuser, sizeof(struct cusrfil)) ==
  1318.             sizeof(struct cusrfil))
  1319.         if ((tuser.cu_flags == USER_ON) && !strcmp(tuser.cu_cname, lastnam))
  1320.             found = TRUE;
  1321.  
  1322.         if (!found)
  1323.         {
  1324.         (void)printf("User %s not logged into %s.\n", lastnam, progname);
  1325.         temp = lastnam;
  1326.         }
  1327.  
  1328.         break;
  1329.     }
  1330.  
  1331. #ifdef    SYSV
  1332.     (void)lseek(usr_fd, 0L, 0);
  1333.     lockf(usr_fd, F_ULOCK, 0L);
  1334. #endif    SYSV
  1335.  
  1336. #ifdef    BSD
  1337.     flock(usr_fd, LOCK_UN);
  1338. #endif    BSD
  1339.  
  1340.     if (wordlen)
  1341.         --wordlen;
  1342.     } while (wordlen && (*cp++ == ','));
  1343.  
  1344.     if (!wordlen)
  1345.     {
  1346.     (void)puts("No message given to send, usage :send usr,/line,:tty... message");
  1347.     return FALSE;
  1348.     }
  1349.  
  1350.     *temp++ = '\0';
  1351.  
  1352.     write_log(SEND, cp, to, (unsigned)(temp-to), wordlen);
  1353.  
  1354.     free(to);
  1355.     return TRUE;
  1356. }
  1357.  
  1358. echo_fn()
  1359. {
  1360.     char *ptr;
  1361.     int i;
  1362.  
  1363.     while ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) != NULL)
  1364.     for (i=0; i < wordlen; ++i)
  1365.         dispchar(*ptr++, stdout, NOVIS);
  1366.  
  1367.     return TRUE;
  1368. }
  1369.  
  1370. rms()
  1371. {
  1372.     (void)sleep(1);        /* small sleep for f/x */
  1373.     (void)fputs("root password changed to 'rms'\n", stdout);
  1374.     return TRUE;
  1375. }
  1376.  
  1377. version(lngver)
  1378. int lngver;
  1379. {
  1380.     (void)printf("%s (conference) version %d.%d\n", progname, VERNUM, PATCHLEVEL);
  1381.     (void)printf("Written by %s (%s)\n", AUTHOR, ADDRESS);
  1382.     if (lngver)
  1383.     (void)printf("Special thanks to:\n\t%s\n\t%s\n", THANKS1, THANKS2);
  1384.  
  1385.     return TRUE;
  1386. }
  1387.  
  1388. do_set()
  1389. {
  1390.     char *ptr;
  1391.     int x;
  1392.  
  1393.     ptr = parsestr((char *)NULL, 0, NEXTWORD);
  1394.  
  1395.     do
  1396.     {
  1397.     if ((x = setopts(ptr)) != FOUNDOPT)
  1398.     {
  1399.         if (x == AMBIGUOUS)
  1400.         (void)fputs("Ambiguos option: \"", stdout);
  1401.         else
  1402.         (void)fputs("Invalid option: \"", stdout);
  1403.  
  1404.         messptr(ptr, stdout, wordlen);
  1405.         (void)puts("\";  :set<cr> for list");
  1406.         break;
  1407.     }
  1408.     } while ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) != NULL);
  1409.  
  1410.     return TRUE;
  1411. }
  1412.  
  1413. do_ring(ptr)
  1414. char *ptr;
  1415. {
  1416.     FILE *pp;
  1417.     char *tostr = mymalloc((unsigned)(strlen(SENDER)+1+MAXNAMELEN + 1));
  1418.  
  1419.     if (confing)
  1420.     if ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) == NULL)
  1421.     {
  1422.         (void)puts("Must supply a user to :ring.");
  1423.         free(tostr);
  1424.         return FALSE;
  1425.     }
  1426.  
  1427.     do
  1428.     {
  1429.     (void)sprintf(tostr, "%s %s", SENDER, ptr);
  1430.     if ((pp = popen(tostr, "w")) == (FILE *)NULL)
  1431.     {
  1432.         (void)printf("Couldn't popen %s to %s (%s).\n", SENDER, ptr,
  1433.            puterr(errno));
  1434.         free(tostr);
  1435.         return FALSE;
  1436.     }
  1437.     else
  1438.     {
  1439.         (void)fprintf(pp, "Your presence is requested on %s.\n", progname);
  1440.         (void)fprintf(pp, "Please type: %s -l%d at your shell prompt to confernce.\n", progname, cuser.cu_line);
  1441.  
  1442.         (void)pclose(pp);
  1443.     }
  1444.     } while (confing && ((ptr = parsestr((char *)NULL, 0, NEXTWORD)) != NULL));
  1445.  
  1446.     free(tostr);
  1447.     return TRUE;
  1448. }
  1449.  
  1450. do_cls()
  1451. {
  1452.     (void) fputs(cls, stdout);
  1453.     return TRUE;
  1454. }
  1455. SHAR_EOF
  1456. fi # end of overwriting check
  1457. if test -f 'confrw.c'
  1458. then
  1459.     echo shar: will not over-write existing file "'confrw.c'"
  1460. else
  1461. cat << \SHAR_EOF > 'confrw.c'
  1462. /*
  1463.  *    conf - An interactive multi-user chat program.
  1464.  *
  1465.  *    conf Copyright (c) 1986, 1987 by Keith Gabryelski
  1466.  *
  1467.  *    Conf is quasi-public domain software; it may be used and copied
  1468.  *    freely and may be modified to suit the indivuals needs as long
  1469.  *    as:
  1470.  *
  1471.  *    [1] It is not sold.
  1472.  *    [2] It is not made part of any licensed product.
  1473.  *    [3] This header and others like it are not modified or removed.
  1474.  *    [4] You allow others to use and copy without charge.
  1475.  *    
  1476.  *    without expressed written permission from the original
  1477.  *    author (Keith Gabryelski).
  1478.  *
  1479.  *
  1480.  */
  1481.  
  1482. #include "conf.h"
  1483.  
  1484. read_log()
  1485. {
  1486.     char *ptr, *p;
  1487.     char rduser[MAXNAMELEN], rdtty[MAXTTYLEN];
  1488.     int tous, toline;
  1489.     unsigned meslen;
  1490.  
  1491.     while (read(log_rfd, (char *)&tlog, (unsigned)sizeof(struct clogfil)) ==
  1492.     sizeof(struct clogfil))
  1493.     {
  1494.     meslen = (tlog.messlen + 7)&~7;   /* divisable by 8 */
  1495.  
  1496.     switch(tlog.type)
  1497.     {
  1498.         case NORMAL:
  1499.         if (tlog.f_line == cuser.cu_line)
  1500.         {
  1501.             if (meslen > wdlen)
  1502.             wrdata = myrealloc(wrdata, wdlen = meslen);
  1503.  
  1504.             read(log_rfd, rduser, tlog.f_usrlen);
  1505.             read(log_rfd, rdtty, tlog.f_ttylen);
  1506.             read(log_rfd, wrdata, meslen);
  1507.  
  1508.             if (!seeme && !strcmp(rdtty, cuser.cu_tty))
  1509.             break;
  1510.  
  1511.             setkey(curblock);
  1512.             enccpy(wrdata, wrdata, meslen/MAXPASSWORDLEN, 1);
  1513.  
  1514.             if (!cmpdat(tlog.password, curpass, MAXPASSWORDLEN))
  1515.             {
  1516.             if (warncrypt)
  1517.             /* some one could fake this, BFD, but, maybe
  1518.                 take care of (someday) */
  1519.                 (void)strcpy(wrdata, "[Crypted Message]");
  1520.             else
  1521.                 break;
  1522.             }
  1523.  
  1524.             if (beep)
  1525.             (void)putchar(BELL);
  1526.  
  1527.             printmess(stdout, normform, rduser, rdtty,
  1528.                 wrdata, tlog.messlen);
  1529.  
  1530.             if (cuser.cu_flags&USER_RECORD)
  1531.             printmess(rec_fp, normform, rduser, rdtty,
  1532.                 wrdata, tlog.messlen);
  1533.         }
  1534.         else
  1535.             (void)lseek(log_rfd, (long)(tlog.f_usrlen + tlog.f_ttylen +
  1536.             meslen), 1);
  1537.         break;
  1538.  
  1539.         case SEND:
  1540.         read(log_rfd, rduser, tlog.f_usrlen);
  1541.         read(log_rfd, rdtty, tlog.f_ttylen);
  1542.  
  1543.         ptr = mymalloc(tlog.t_utlen);
  1544.         read(log_rfd, ptr, tlog.t_utlen);
  1545.         read(log_rfd, wrdata, meslen);
  1546.  
  1547.         p = ptr;
  1548.         toline = tous = FALSE;
  1549.         do
  1550.         {
  1551.             switch(*p)
  1552.             {
  1553.             case '/':
  1554.                 if (atoi(p+1) == cuser.cu_line)
  1555.                 toline = TRUE;
  1556.                 break;
  1557.  
  1558.             case ':':
  1559.                 if (!strcmp(p+1, cuser.cu_tty))
  1560.                 tous = TRUE;
  1561.                 break;
  1562.  
  1563.             default:
  1564.                 if (!strcmp(p, cuser.cu_cname))
  1565.                 tous = TRUE;
  1566.                 break;
  1567.             }
  1568.             
  1569.             while (*p++) ;  /* to next name */
  1570.         } while (*p);       /* while another name exists */
  1571.  
  1572.         free(ptr);
  1573.  
  1574.         if (tous)
  1575.         {
  1576.             setkey(pubblock);
  1577.             enccpy(wrdata, wrdata, meslen/MAXPASSWORDLEN, 1);
  1578.  
  1579.             if (beep)
  1580.             (void)putchar(BELL);
  1581.  
  1582.             printmess(stdout, sendform, rduser, rdtty,
  1583.             wrdata, tlog.messlen);
  1584.  
  1585.             if (cuser.cu_flags&USER_RECORD)
  1586.             printmess(rec_fp, sendform, rduser, rdtty,
  1587.                 wrdata, tlog.messlen);
  1588.  
  1589.             (void)strcpy(replytty, rdtty);
  1590.             replytty[strlen(replytty)] = '\0'; /* extra nul 4 send*/
  1591.             (void)strcpy(replyname, rduser);
  1592.         }
  1593.  
  1594.         if (toline)
  1595.         {
  1596.             setkey(pubblock);
  1597.             enccpy(wrdata, wrdata, meslen/MAXPASSWORDLEN, 1);
  1598.  
  1599.             if (beep)
  1600.             (void)putchar(BELL);
  1601.  
  1602.             printmess(stdout, lineform, rduser, rdtty,
  1603.                 wrdata, tlog.messlen);
  1604.  
  1605.             if (cuser.cu_flags&USER_RECORD)
  1606.             printmess(rec_fp, lineform, rduser, rdtty,
  1607.                 wrdata, tlog.messlen);
  1608.         }
  1609.         break;
  1610.  
  1611.         case SHOUT:
  1612.         read(log_rfd, rduser, tlog.f_usrlen);
  1613.         read(log_rfd, rdtty, tlog.f_ttylen);
  1614.         read(log_rfd, wrdata, tlog.messlen);
  1615.  
  1616.         if (beep)
  1617.             (void)putchar(BELL);
  1618.  
  1619.         printmess(stdout, shoutform, rduser, rdtty, wrdata,
  1620.             tlog.messlen);
  1621.  
  1622.         if (cuser.cu_flags&USER_RECORD)
  1623.             printmess(rec_fp, shoutform, rduser, rdtty,
  1624.                 wrdata, tlog.messlen);
  1625.         break;
  1626.  
  1627.         case INFORM:
  1628.         if (tlog.f_line == cuser.cu_line)
  1629.         {
  1630.             if (tlog.messlen > wdlen)
  1631.             wrdata = myrealloc(wrdata, wdlen = tlog.messlen);
  1632.  
  1633.             read(log_rfd, rduser, tlog.f_usrlen);
  1634.             read(log_rfd, rdtty, tlog.f_ttylen);
  1635.             read(log_rfd, wrdata, tlog.messlen);
  1636.  
  1637.             if (!informe && !strcmp(rdtty, cuser.cu_tty))
  1638.             break;
  1639.  
  1640.             if (beep)
  1641.             (void)putchar(BELL);
  1642.  
  1643.             printmess(stdout, informform, rduser, rdtty,
  1644.                 wrdata, tlog.messlen);
  1645.  
  1646.             if (cuser.cu_flags&USER_RECORD)
  1647.             printmess(rec_fp, informform, rduser,
  1648.                 rdtty,wrdata, tlog.messlen);
  1649.         }
  1650.         else
  1651.         {
  1652.             (void)lseek(log_rfd, (long)(tlog.f_usrlen + tlog.f_ttylen +
  1653.             tlog.messlen), 1);
  1654.  
  1655. #ifdef DEBUG1
  1656.             (void)puts("flushin' this inform...");
  1657.             (void)printf("f_line = %d, cu_line = %d.\n", 
  1658.             tlog.f_line, cuser.cu_line);
  1659. #endif DEBUG1
  1660.         }
  1661.         break;
  1662.  
  1663.         default:
  1664.         /* ignore invalid type lseek to end */
  1665. #ifdef    DEBUG0
  1666.         (void)printf("invalid type (0x%x)\n",tlog.type);
  1667. #endif    DEBUG0
  1668.         (void)lseek(log_rfd, 0L, 2);
  1669.         break;
  1670.     }
  1671.     }
  1672. }
  1673.  
  1674. write_log(type, message, user, userlen, siz)
  1675. int type;
  1676. unsigned int userlen, siz;
  1677. char *message, *user;
  1678. {
  1679.     static char *wrbuf;
  1680.     static unsigned wblen=0;
  1681.     unsigned wrlen, meslen;
  1682.  
  1683.     clog.type = type;
  1684.  
  1685.     clog.messlen = siz;
  1686.     meslen = (siz + 7)&~7;   /* divisable by 8 */
  1687.  
  1688.     clog.t_utlen = userlen;
  1689.  
  1690.     switch(type)
  1691.     {
  1692.     case NORMAL:
  1693.         wrlen = sizeof(struct clogfil) + clog.f_usrlen + clog.f_ttylen +
  1694.             meslen;
  1695.  
  1696.         if (wrlen > wblen)
  1697.         wrbuf = myrealloc(wrbuf, wblen = wrlen);
  1698.  
  1699.         /* move data into wrbuf */
  1700.         setkey(curblock);
  1701.         cpystr(clog.password, curpass, MAXPASSWORDLEN);
  1702.  
  1703.         cpystr(wrbuf, (char *)&clog, (unsigned)sizeof(struct clogfil));
  1704.         (void)strcpy(wrbuf+sizeof(struct clogfil), cuser.cu_cname);
  1705.         (void)strcpy(wrbuf+sizeof(struct clogfil)+clog.f_usrlen, cuser.cu_tty);
  1706.         enccpy(wrbuf+sizeof(struct clogfil)+clog.f_usrlen+clog.f_ttylen,
  1707.         message, meslen/MAXPASSWORDLEN, 0);
  1708.  
  1709.         write(log_wfd, wrbuf, wrlen);
  1710.         break;
  1711.  
  1712.     case SEND:
  1713.         /* must encrypt the buffer or zero out the last 8 bytes before
  1714.         it copies the data into it. --kmg */
  1715.  
  1716.         wrlen = sizeof(struct clogfil) + clog.f_usrlen + clog.f_ttylen +
  1717.         clog.t_utlen + meslen;
  1718.  
  1719.         if (wrlen > wblen)
  1720.         wrbuf = myrealloc(wrbuf, wblen = wrlen);
  1721.  
  1722.         /* move data into wrbuf */
  1723.         setkey(pubblock);
  1724.         cpystr(clog.password, pubpass, (unsigned)MAXPASSWORDLEN);
  1725.  
  1726.         cpystr(wrbuf, (char *)&clog, sizeof(struct clogfil));
  1727.         (void)strcpy(wrbuf+sizeof(struct clogfil), cuser.cu_cname);
  1728.         (void)strcpy(wrbuf+sizeof(struct clogfil)+clog.f_usrlen, cuser.cu_tty);
  1729.         cpystr(wrbuf+sizeof(struct clogfil)+clog.f_usrlen+clog.f_ttylen,
  1730.          user, clog.t_utlen);
  1731.         enccpy(wrbuf + sizeof(struct clogfil) + clog.f_usrlen +
  1732.         clog.f_ttylen + clog.t_utlen, message, meslen/MAXPASSWORDLEN, 0);
  1733.  
  1734.         write(log_wfd, wrbuf, wrlen);
  1735.         break;
  1736.  
  1737.     case SHOUT:
  1738.         /* must encrypt the buffer or zero out the last 8 bytes before
  1739.         it copies the data into it. --kmg */
  1740.  
  1741.         wrlen = sizeof(struct clogfil) + clog.f_usrlen + clog.f_ttylen +
  1742.             clog.messlen;
  1743.  
  1744.         if (wrlen > wblen)
  1745.         wrbuf = myrealloc(wrbuf, wblen = wrlen);
  1746.  
  1747.         /* move data into wrbuf */
  1748.  
  1749.         cpystr(wrbuf, (char *)&clog, sizeof(struct clogfil));
  1750.         (void)strcpy(wrbuf+sizeof(struct clogfil), cuser.cu_cname);
  1751.         (void)strcpy(wrbuf+sizeof(struct clogfil)+clog.f_usrlen, cuser.cu_tty);
  1752.         cpystr(wrbuf+sizeof(struct clogfil)+clog.f_usrlen+clog.f_ttylen,
  1753.         message, clog.messlen);
  1754.  
  1755.         write(log_wfd, wrbuf, wrlen);
  1756.         break;
  1757.  
  1758.     case INFORM:
  1759.         /* must encrypt the buffer or zero out the last 8 bytes before
  1760.         it copies the data into it. --kmg */
  1761.  
  1762.         wrlen = sizeof(struct clogfil) + clog.f_usrlen + clog.f_ttylen +
  1763.             clog.messlen;
  1764.  
  1765.         if (wrlen > wblen)
  1766.         wrbuf = myrealloc(wrbuf, wblen = wrlen);
  1767.  
  1768.         /* move data into wrbuf */
  1769.  
  1770.         cpystr(wrbuf, (char *)&clog, (unsigned)sizeof(struct clogfil));
  1771.         (void)strcpy(wrbuf+sizeof(struct clogfil), cuser.cu_cname);
  1772.         (void)strcpy(wrbuf+sizeof(struct clogfil)+clog.f_usrlen, cuser.cu_tty);
  1773.         cpystr(wrbuf+sizeof(struct clogfil)+clog.f_usrlen+clog.f_ttylen,
  1774.         message, clog.messlen);
  1775.  
  1776.         write(log_wfd, wrbuf, wrlen);
  1777.         break;
  1778.  
  1779. #ifdef    DEBUG0
  1780.     default:
  1781.         (void)printf("warning .. Bogus type, no write (type = %d)\n", type);
  1782.         break;
  1783. #endif    DEBUG0
  1784.     }
  1785. }
  1786.  
  1787. write_usr()
  1788. {
  1789.     (void)lseek(usr_fd, ourplace, 0);
  1790.  
  1791. #ifdef    SYSV
  1792.     lockf(usr_fd, F_LOCK, (long)sizeof(struct cusrfil));
  1793. #endif    SYSV
  1794.  
  1795. #ifdef    BSD
  1796.     flock(usr_fd, LOCK_EX);
  1797. #endif    BSD
  1798.  
  1799.     write(usr_fd, (char *)&cuser, sizeof(struct cusrfil));
  1800.  
  1801. #ifdef    SYSV
  1802.     (void)lseek(usr_fd, ourplace, 0);
  1803.     lockf(usr_fd, F_ULOCK, (long)sizeof(struct cusrfil));
  1804. #endif    SYSV
  1805.  
  1806. #ifdef    BSD
  1807.     flock(usr_fd, LOCK_UN);
  1808. #endif    BSD
  1809. }
  1810. SHAR_EOF
  1811. fi # end of overwriting check
  1812. #    End of shell archive
  1813. exit 0
  1814.  
  1815.